#ifndef DELEGATE_H
#define DELEGATE_H

#include <QStyledItemDelegate>
#include <QModelIndex>
#include <QObject>
#include <QSize>
#include <QSpinBox>
#include <QComboBox>
#include <QCheckBox>
#include <QStringList>
#include <QDoubleSpinBox>
#include <QLineEdit>
#include<QListView>

#include "experiment.h"

class SpinBoxDelegate : public  QStyledItemDelegate
{
    Q_OBJECT

public:
    SpinBoxDelegate(QObject *parent = 0);

    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
                          const QModelIndex &index) const;

    void setEditorData(QWidget *editor, const QModelIndex &index) const;
    void setModelData(QWidget *editor, QAbstractItemModel *model,
                      const QModelIndex &index) const;

    //void updateEditorGeometry(QWidget *editor,
    //    const QStyleOptionViewItem &option, const QModelIndex &index) const;

private:

};
class DoubleSpinBoxDelegate : public  QStyledItemDelegate
{
    Q_OBJECT

public:
    DoubleSpinBoxDelegate(QObject *parent = 0);

    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
                          const QModelIndex &index) const;

    void setEditorData(QWidget *editor, const QModelIndex &index) const;
    void setModelData(QWidget *editor, QAbstractItemModel *model,
                      const QModelIndex &index) const;

    //void updateEditorGeometry(QWidget *editor,
    //    const QStyleOptionViewItem &option, const QModelIndex &index) const;

private:

};

class LineEditDelegate : public  QStyledItemDelegate
{
    Q_OBJECT

public:
    LineEditDelegate(QObject *parent = 0,int style=0);

    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
                          const QModelIndex &index) const;

    void setEditorData(QWidget *editor, const QModelIndex &index) const;
    void setModelData(QWidget *editor, QAbstractItemModel *model,
                      const QModelIndex &index) const;

    //void updateEditorGeometry(QWidget *editor,
    //    const QStyleOptionViewItem &option, const QModelIndex &index) const;

private:
    int style;//不同类型处理方式不同
};

class ComboxDelegate : public  QStyledItemDelegate
{
    Q_OBJECT

public:
    ComboxDelegate(QObject *parent = 0,int style=0,Experiment *pExperiment=NULL);

    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
                          const QModelIndex &index) const;

    void setEditorData(QWidget *editor, const QModelIndex &index) const;
    void setModelData(QWidget *editor, QAbstractItemModel *model,
                      const QModelIndex &index) const;

    //void updateEditorGeometry(QWidget *editor,
    //    const QStyleOptionViewItem &option, const QModelIndex &index) const;
private:
    int style;//不同类型处理方式不同
    Experiment *pExperiment;
};

class CheckBox : public  QStyledItemDelegate
{
    Q_OBJECT

public:
    CheckBox(QObject *parent = 0,int style=0);

    void paint(QPainter *painter, const QStyleOptionViewItem &option,
                              const QModelIndex &index) const;

QRect CheckBoxRect(const QStyleOptionViewItem &viewItemStyleOptions)const;
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option,  const QModelIndex &index);

private:
QStyleOptionButton *checkBoxOption;
int style;//不同类型处理方式不同
};

#endif // DELEGATE_H
